#include <STC89C5xRC.H>

void Delayms(unsigned int xms)
{
	unsigned char i, j;
  while(xms)
	{
		i = 2;
		j = 199;
		do
		{
			while (--j);
		} while (--i);
		xms--;
	}
}

void main()
{
	unsigned char lednum = 0;
	while(1)
	{
		if(P31 == 0)
		{
			Delayms(20);
			while(P31 == 0);
			Delayms(20);
			lednum++;
			P2 = ~lednum;
		}
	}
}
